package com.example.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.demo.entity.User;
import com.example.demo.mapper.UserMapper;
import com.example.demo.service.UserService;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {
    @Override
    public long countUsersByAgeRange(Integer minAge, Integer maxAge) {
        // 使用QueryWrapper构建查询条件
        QueryWrapper<User> queryWrapper = new QueryWrapper<>();
        if (minAge != null) {
            queryWrapper.ge("age", minAge);  // age >= minAge
        }
        if (maxAge != null) {
            queryWrapper.le("age", maxAge);  // age <= maxAge
        }
        return count(queryWrapper);  // 调用MyBatis Plus提供的count方法
    }
} 